package com.hnichr.ump.common.assessment.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.hnichr.ump.common.entity.UmpEntity;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.Date;


@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "t_assessment_invite",indexes = {@Index(columnList = "START_TIME_"),@Index(columnList = "END_TIME_")})
@Schema(description = "受测邀请")
public class Invite extends UmpEntity {

    @Id
    @Generator
    @Column(name = "ID_", updatable = false)
    @Schema(description = "ID")
    private String id;

    @Column(name = "TENANT_ID_")
    @Schema(description = "租户")
    @Dict(dicCode = "BEISEN_ACTIVITY_TENANT")
    private String tenantId;

    @Column(name = "TESTEE_ID_")
    @Schema(description = "受测者ID")
    private String testeeId ;

    @Column(name = "ACTIVITY_ID_")
    @Schema(description = "活动ID")
    private String activityId;

    @Column(name = "ACTIVITY_NAME_",length = 500)
    @Schema(description = "测评活动名称")
    private String activityName;

    @Column(name = "EMAIL_")
    @Schema(description = "邮箱")
    private String email;

    @Column(name = "SN_")
    @Schema(description = "通行证")
    private String sn;

    @Column(name = "TEST_URL_")
    @Schema(description = "答题url")
    private String testUrl ;

    @Column(name = "LOGIN_URL_")
    @Schema(description = "登录url")
    private String loginUrl ;

    @Column(name = "START_TIME_")
    @Schema(description = "测评生效时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date startTime ;

    @Column(name = "END_TIME_")
    @Schema(description = "测评失效时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date endTime;

    @Column(name = "STATE_")
    @Schema(description = "作答状态，1：未开始，2：作答中，3：已完成")
    @Dict(dicCode = "BEISEN_ACCESSMENT_STATE")
    private String state ;

    @Column(name = "INVITE_RESULT_")
    @Schema(description = "邀请状态，1：成功，9：失败，99：接口错误")
    @Dict(dicCode = "BEISEN_INVITE_RESULT")
    private String inviteResult;

    @Column(name = "RESULT_STATE_")
    @Schema(description = "答题结果同步状态，0-未同步  1-已同步")
    private String resultState;


    @Transient
    @Schema(description = "受测者")
    private Testee testee ;

    @Transient
    @Schema(description = "结果")
    private TesteeResult result;


    public enum STATE{
        NOT_STARTED("1"),ASSESSMENT_PROCESSING("2"),ASSESSMENT_COMPLATED("3");
        private String code;

        STATE(String code){
            this.code = code;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }
    }

    public enum INVITE_RESULT{
        SUCCESS("1"),FAILED("9"),INTERFACE_ERROR("99");
        private String code;

        INVITE_RESULT(String code){
            this.code = code;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }
    }

    public enum RESULT_STATE{
        NOT_SYNC("0"),SYNCED("1");
        private String code;

        RESULT_STATE(String code){
            this.code = code;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }
    }

}
